var memberIdInfos = {},
    tooltip = null;
$(document).on("click", ".close-tooltip", function() { tooltip.tooltipster("close") }), $(function() {
    -1 != navigator.userAgent.indexOf("uni-app") && window.__banksteelToken && n("user_token", window.__banksteelToken), $.ajaxSetup({ beforeSend: function(e) { var t = this.url.split("?")[0].replace(/http(s)?:\/\//, ""); "member.banksteel.com" == (t = t.split("/")[0]) && e.setRequestHeader("Accept", "application/json") }, complete: function(e) { if (401 == e.status) { requestUrl = this.url.split("?")[0].replace(/http(s)?:\/\//, ""), -1 == ["member.banksteel.com/resource/api/v1/user/get-search-record", "member.banksteel.com/resource/api/v1/user/get-consult-status", "member.banksteel.com/member/header"].indexOf(requestUrl) && (window.location.href = "//login.banksteel.com/login.htm?mybackurl=" + window.location.href) } } });
    var e = a("user_token"),
        t = { t1: 0, t2: 0 };

    function n(e, t, a) {
        var s = a || 0;
        s ? $.cookie(e, t, { expires: s, domain: "banksteel.com", path: "/" }) : $.cookie(e, t, { domain: "banksteel.com", path: "/" })
    }

    function a(e) { var t = $.cookie(e); return t = t || "" }

    function s() {
/*
        $.ajax({
            type: "get",
            url: "",
            cache: !1,
            xhrFields: { withCredentials: !0 },
            success: function(e) {
                if (e) {
                    var t = "";
                    e.data.forEach(function(e) { t += '<a style="color:#999" href="//res.banksteel.com?cn=' + encodeURI(e) + '&seartop=1">' + e + "&nbsp;&nbsp;</a>" }), $(".header .search-top5").html(t)
                }
            }
        })
*/
    }

    function o(a, s) {
        e && $.ajax({
            type: "get",
            url: "//member.banksteel.com/resource/api/v1/user/get-search-record",
            xhrFields: { withCredentials: !0 },
            data: { type: a },
            success: function(e) {
                if (e.success) {
                    var t = "";
                    e.data.forEach(function(e) { t += '<li class="history"><a href="//' + (1 == a ? "shop" : "res") + ".banksteel.com?kw=" + encodeURI(e) + '"><span class="sear-res-l">' + e + "</span></a></li>" }), "both" == s ? ($(".top-search-fixed .sear-res").html(t), $(".header .sear-res").html(t)) : "float" == s ? $(".top-search-fixed .sear-res").html(t) : $(".header .sear-res").html(t)
                }
            }
        })
    }

    function r(e, a, s) {
        $.ajax({
            type: "get",
            url: "//api.banksteel.com/consult/v1/home/get-keyword-options",
            xhrFields: { withCredentials: !0 },
            data: { keyword: e, type: a },
            success: function(e) {
                if (e.success) {
                    var t = "";
                    e.data.forEach(function(e) { t += '<li class="keyOption"><a href="//' + (1 == a ? "shop" : "res") + ".banksteel.com?from=searchbar&kw=" + encodeURI(e) + '"><span class="sear-res-l">' + e + "</span></a></li>" }), s ? $(".top-search-fixed .sear-res").html(t) : $(".header .sear-res").html(t)
                }
            }
        })
    }
    $(".topbar li").each(function() { $(this).mouseenter(function() { $(this).addClass("menu-hover") }), $(this).mouseleave(function() { $(this).removeClass("menu-hover") }) }), $(".msg-top li").click(function() { $(this).addClass("active").siblings().removeClass("active"), 0 == $(this).index() ? ($(".msg-wrap").show(), $(".account-msg").hide(), getMessageList(2)) : 1 == $(this).index() && ($(".msg-wrap").hide(), $(".account-msg").show(), getMessageList(1)) }), $(".topbar .logon-menber-info .menu-bd a").click(function() {
        var e = $(this).html();
        console.log(e)
    }), $(".hd-search-title span").each(function() { $(this).click(function() { $(this).siblings().removeClass("active-tit"), $(this).addClass("active-tit"); var e = $(this).parents(".header").find(".hd-search").find(".search-combobox-input").find("#kwInput1"); "商品" == $(this).html() ? (e.val() ? r(e.val(), 0) : o(0), e.attr("placeholder", "请输入品名、规格、材质、钢厂等，如螺纹钢 10*9"), $(".page-chaoshi #keyword").show(), $(".page-chaoshi #kwInput1").hide()) : (e.val() ? r(e.val(), 1) : o(1), e.attr("placeholder", "请输入公司名称、简称"), $(".page-chaoshi #keyword").hide(), $(".page-chaoshi #kwInput1").show()) }) }), $(".m-nav .kaidain").on("click", function() {
        var e = a("user_token");
        window.location.href = e ? "//member.banksteel.com/console/#/seller/auth-member" : "//login.banksteel.com/login.htm?mybackurl=" + window.location.href
    }), $(".search-triggers").hover(function() { $(".search-triggers").addClass("search-triggers-hover") }, function() { $(".search-triggers").removeClass("search-triggers-hover") }), $(".header-nav-btn .mn-ico2").hover(function() { $(".cart-panel").show() }, function() { $(".cart-panel").hide() }), $(".header-nav-btn .cart-panel").hover(function() { $(".mn-ico2").addClass("m-nav-hover"), $(".cart-panel").show() }, function() { $(".mn-ico2").removeClass("m-nav-hover"), $(".cart-panel").hide() }), $(".nav-allsort").hover(function() { $(".allsort-list").show() }, function() { $(".allsort-list").hide() }), $(".page-index .nav-all").unbind(), $(".allsort-list .item-li").mouseenter(function() { $(this).addClass("hover") }), $(".allsort-list .item-li").mouseleave(function() { $(this).removeClass("hover") }), $(window).scroll(function() { 150 <= $(document).scrollTop() ? ($(".top-search-fixed").slideDown(300), $(".header  .search-result").hide()) : $(".top-search-fixed").slideUp(100) }), $(document).on("change", ".top-search-fixed .type-search select", function() { "商品" == $(this).val() ? $(this).parents("form").find(".search-combobox input").attr("placeholder", "请输入品名、规格、材质、钢厂等，如螺纹钢 10*9") : $(this).parents("form").find(".search-combobox input").attr("placeholder", "请输入公司名称、简称") }), $("#search .search-combobox-input input").click(function(e) { e.stopPropagation(), $(".header .search-result").show(), 0 < $(".page-chaoshi #keyword").length && ($(".page-chaoshi #keyword").is(":hidden") ? ($(".page-chaoshi .sear-res").html(""), $(".page-chaoshi .sear-history").hide()) : ($(".page-chaoshi .sear-res").html('<li><a href="javascript:Chaoshi.searchKeyword(`建筑钢材`);"><span class="sear-res-l">建筑钢材</span></a></li><li><a href="javascript:Chaoshi.searchKeyword(`热卷`);"><span class="sear-res-l">热卷</span></a></li><li><a href="javascript:Chaoshi.searchKeyword(`中厚板`);"><span class="sear-res-l">中厚板</span></a></li><li><a href="javascript:Chaoshi.searchKeyword(`冷轧涂镀`);"><span class="sear-res-l">冷轧涂镀</span></a></li><li><a href="javascript:Chaoshi.searchKeyword(`型钢`);"><span class="sear-res-l">型钢</span></a></li>'), $(".page-chaoshi .sear-history").show())) }), $("#search .search-combobox-input #kwInput1").keyup(function() {
        var e = this;
        clearTimeout(t.t1), t.t1 = setTimeout(function() { $(e).val() ? r($(e).val(), "商品" == $(".active-tit").text() ? 0 : 1) : o("商品" == $(".active-tit").text() ? 0 : 1) }, 300)
    }), $(document).click(function() { $(".search-result").hide() }), $("#search-float .search-combobox-input input").click(function(e) { e.stopPropagation(), $(".top-search-fixed .search-result").show() }), $("#search-float .search-combobox-input input").keyup(function() {
        var e = this;
        clearTimeout(t.t2), t.t2 = setTimeout(function() { $(e).val() ? r($(e).val(), "商品" == $("#search-type .on").text() ? 0 : 1, !0) : o("商品" == $("#search-type .on").text() ? 0 : 1, "float") }, 300)
    }), $("#search-float #search-type li").click(function() { $(this).addClass("on"), $(this).siblings().removeClass("on"), $("#search-float .type-search .tit span").text($(this).text()); var e = $("#search-float .search-combobox-input #kwInput1-f"); "商品" == $(this).text() ? e.val() ? r(e.val(), 0, !0) : o(0, "float") : e.val() ? r(e.val(), 1, !0) : o(1, "float") }), $("#search #kwInput1").change(function() { $("#search-float .search-combobox-input #kwInput1-f").val($(this).val()) }), $("#search-float .search-combobox-input #kwInput1-f").change(function() { $("#search #kwInput1").val($(this).val()) }), $(document).on("click", ".hd-search .search-top5 a", function() { sensors.track("topSearchClick", { prior_source: document.referrer, current_page: window.location.href, key_word: $(this).text(), key_word_type: "推荐词", search_type: $(".hd-search-title .active-tit").text() }, function() {}) }), $(document).on("click", ".sear-res .keyOption", function() { sensors.track("topSearchClick", { prior_source: document.referrer, current_page: window.location.href, key_word: $(this).find(".sear-res-l").text(), key_word_type: "联想词", search_type: $(".hd-search-title .active-tit").text() }, function() {}) }), $(document).on("click", ".sear-res .history", function() { sensors.track("topSearchClick", { prior_source: document.referrer, current_page: window.location.href, key_word: $(this).find(".sear-res-l").text(), key_word_type: "历史词", search_type: $(".hd-search-title .active-tit").text() }, function() {}) }), $(document).on("click", ".header-nav-btn1.mn-ico3", function() { sensors.track("fastBuyClick", { prior_source: document.referrer, current_page: window.location.href }, function() {}) }), $(document).on("click", ".side-login .show-content", function() { sensors.track("fastBuyClick", { prior_source: document.referrer, current_page: "钢银首页主Banner右侧的“快速求购”" }, function() {}) }), $(".allsort-list").on("click", ".item-list-sub2 a", function() {
        var e = $(this).closest(".item-list").attr("id").substring(10);
        sensors.track("adCategoryMenuClick", { advert_category: { jiancai: "建筑钢材", rejuan: "热卷", zhongban: "中厚板", lengdu: "冷轧涂镀", xinggang: "型钢", guancai: "管材", ytg: "优特钢" }[e], advert_url: $(this).attr("href"), advert_order: $(this).parent().index() + 1 }, function() {})
    }), $(document).on("click", ".btn-ksqg", function() { a("user_token") ? window.location.href = "//caigou.banksteel.com" : window.location.href = "//login.banksteel.com/login.htm?mybackurl=" + window.location.href }), e && $.ajax({
        type: "POST",
        url: "//login.banksteel.com/sso/verifyToken.htm",
        data: { token: e },
        success: function(e) {
            if (e && 12 != e.code && e.content && e.content.loginUName) {
                $(".logon").show(), $(".unlogin").hide();
                var t = e.content.loginUName,
                    a = e.content.loginName,
                    s = e.content.isSystemPortrait ? e.content.portraitUrl50 : "//a1.gystatic.com/user/" + e.content.portraitUrl50;
                $(".user-name").text(t), $(".user-tel").text(a), $(".content1-infor1").html('<img src="' + s + '">'), $(".side-login-icon").html('<img src="' + s + '">'), $(".page-index #telephone1").val(a), $.cookie("loginUID", e.content.loginUID, { domain: "banksteel.com", path: "/" }), n("login_name", encodeURI(e.content.loginUName), 1), n("login_tel", e.content.loginName, 1), n("login_memberid", e.content.memberId, 1), $(".messageCount") && ($("#showMessage").show(), getMessageCount(), setInterval(getMessageCount, 6e4))
            }
        }
    }), e && $.ajax({ type: "get", url: "//member.banksteel.com/resource/api/v1/user/get-consult-status", xhrFields: { withCredentials: !0 }, success: function(e) { e && (n("userStatus", e.data.status, 1), 0 == e.data.status || 1 == e.data.status || 2 == e.data.status ? $(".m-nav .myshop").hide() : ($(".m-nav .myshop").show(), $(".m-nav .myshop").attr("data-href", "//shop.banksteel.com/" + e.data.consultShopId))) } }), $(".m-nav .myshop").click(function() { window.location.href = $(this).attr("data-href") }), e && ($.ajax({
        type: "get",
        url: "//member.banksteel.com/member/header",
        xhrFields: { withCredentials: !0 },
        success: function(e) {
            if (e && (n("user_member_info", e, 1), e.memberInfos && 0 != e.memberInfos.length || $(".logon-menber-info").hide().next().hide(), $(".logon-menber-info .menu-hd a").html(e.memberName), e.memberInfos)) {
                var t = e.userName,
                    a = [],
                    s = [];
                e.memberInfos.forEach(function(e) { memberIdInfos[e.memberId] = e.memberName, a.push(e.memberId + ""), s.push(e.memberName) }), sensors.setProfile({ userName: t, memberName: s, memberId: a });
                for (var o = "", r = 0; r < e.memberInfos.length; r++) o += 0 < r ? '<a target="_top" data-id="' + e.memberInfos[r].memberId + '" >' + e.memberInfos[r].memberName + "</a>" : '<a class="first" target="_top" data-id="' + e.memberInfos[r].memberId + '" >' + e.memberInfos[r].memberName + "</a>";
                $(".logon-menber-info .menu-bd-panel").html(o), tooltip = $(".tooltip").tooltipster({ theme: "tooltipster-shadow", trigger: "custom" })
            }
        },
        error: function() { $(".logon-menber-info").hide().next().hide() }
    }), $.ajax({ type: "get", url: "//member.banksteel.com/member/common/user/status", xhrFields: { withCredentials: !0 }, success: function(e) { e && (e.haveMember ? $(".user-status").hide() : $(".user-status").show(), e.memberRealName ? ($(".member-status-no").hide(), $(".member-status-is").show()) : ($(".member-status-no").show(), $(".member-status-is").hide())) }, error: function() { $(".user-status").hide(), $(".member-status-no").hide(), $(".member-status-is").hide() } })), $(document).on("click", ".user-status", function() { window.location.href = "//member.banksteel.com/console/#/member/member-identify/company-identify" }), $(document).on("click", ".member-status-no", function() { window.location.href = "//member.banksteel.com/console/#/member/member-list" }), $(".logon-menber-info").on("click", ".menu-bd a", function() {
        var e = $(this).attr("data-id");
        $.ajax({ type: "post", url: "//member.banksteel.com/member/header/switch-member", xhrFields: { withCredentials: !0 }, data: { currentMemberId: e }, success: function() { n("login_memberid", e, 1), window.location.reload() }, error: function() { console.log("err:" + result) } })
    }), 0 < $(".header .search-top5").length && (s(), setInterval(function() { s() }, 18e4)), o(0, "both"), $(".topbar .user-login").attr("href", "//login.banksteel.com/login.htm?mybackurl=" + window.location.href)
});
var params = {},
    param_br = params.sp;
param_br = params.ml, param_br = params.br, param_br = params.pi;

function searchByParam(e, t, a, s, o) {
    $(document.body);
    var r, n = $("<form method='post'></form>");
    if (url = "//chaoshi.banksteel.com/", null != a) { var i = $("<input type='hidden'>"); "51" == s ? url = "//chaoshi.banksteel.com/jiancai.htm" : "52" == s ? url = "//chaoshi.banksteel.com/rejuan.htm" : "53" == s ? url = "//chaoshi.banksteel.com/zhonghouban.htm" : "54" == s ? url = "//chaoshi.banksteel.com/lengzha.htm" : "55" == s ? url = "//chaoshi.banksteel.com/xinggang.htm" : "56" == s ? url = "//chaoshi.banksteel.com/guancai.htm" : "57" == s ? url = "//chaoshi.banksteel.com/youte.htm" : "58" == s && (url = "//chaoshi.banksteel.com/daigang.htm"), params[a] = s, i.attr({ name: a }), i.val(params[a]), n.append(i) }
    n.attr({ action: url }), null != e && (params[e] = t, (r = $("<input type='hidden'>")).attr({ name: e }), r.val(params[e]), n.append(r));
    if (o) {
        var c = $("<input type='hidden'>");
        c.attr({ name: "txt" }), c.val($(o).text()), n.append(c)
    }
    n.appendTo(document.body), n.submit(), document.body.removeChild(n[0])
}
var flag = "";

function checkKwInput(e) {
    var t = "float" == e ? $("#kwInput1-f") : $("#kwInput1"),
        a = "float" == e ? $("#kwInput2-f") : $("#kwInput2"),
        s = $.trim(t.val());
    "请输入关键词查询" == s || "" == s ? a.val("") : a.val(t.val()), a.val(a.val());
    var o = "商品";
    if ("1" == flag || "" == flag)
        if ("float" == e) "店铺" == $("#search-type .on").text() ? ($("#search-float").attr("action", "//shop.banksteel.com"), o = "店铺") : $("#search-float").attr("action", "//res.banksteel.com");
        else if ("店铺" == $(".active-tit").text()) $("#search").attr("action", "//shop.banksteel.com"), o = "店铺";
    else {
        if (0 < $(".page-chaoshi").length) return sensors.track("topSearchClick", { prior_source: document.referrer, current_page: window.location.href, key_word: t.val(), key_word_type: "超市用户输入", search_type: o }, function() {}), !1;
        $("#search").attr("action", "//res.banksteel.com")
    }
    return sensors.track("topSearchClick", { prior_source: document.referrer, current_page: window.location.href, key_word: t.val(), key_word_type: "用户输入", search_type: o }, function() {}), !0
}({ addCookie: function() { document.cookie = "PAGECODE=" + escape(this.uuid()) + ";expires=" + new Date("2050-1-1") + ";domain=banksteel.com" }, exists: function() { var e = new RegExp("(^| )PAGECODE=([^;]*)(;|$)"); return !!document.cookie.match(e) }, uuid: function() { for (var e = [], t = "0123456789abcdef", a = 0; a < 36; a++) e[a] = t.substr(Math.floor(16 * Math.random()), 1); return e[14] = "4", e[19] = t.substr(3 & e[19] | 8, 1), e[8] = e[13] = e[18] = e[23] = "-", e.join("") }, generate: function() { try { this.exists() || this.addCookie() } catch (e) { console && console.error && console.error(e) } } }).generate();
var ids = [];

function getMessageCount() {
    getCookie("user_token") && $.ajax({
        type: "GET",
        url: "//member.banksteel.com/message/rest/message_user_web/unread/num",
        contentType: "application/json;charset=utf-8",
        data: "businessType=3",
        dataType: "json",
        xhrFields: { withCredentials: !0 },
        success: function(e) {
            var t = e.accountNum + e.businessNum;
            $(".msg-cont .trade-msg").html(e.businessNum), $(".msg-cont .account-num").html(e.accountNum), $(".messageCountDiv").css("display", ""), 99 <= t ? $(".messageCount").html("99+") : $(".messageCount").html(t), e.businessNum ? ($(".msg-wrap").show(), $(".account-msg").hide(), $(".msg-top li").removeClass("active"), $(".msg-top li").eq(0).addClass("active"), getMessageList(2)) : e.accountNum ? ($(".msg-wrap").hide(), $(".account-msg").show(), $(".msg-top li").removeClass("active"), $(".msg-top li").eq(1).addClass("active"), getMessageList(1)) : ($(".msg-wrap").show(), $(".account-msg").hide(), $(".msg-top li").removeClass("active"), $(".msg-top li").eq(0).addClass("active"), getMessageList(2))
        },
        error: function(e) { console.log(e) }
    })
}

function getMessageList(s) {
    $.ajax({
        type: "get",
        url: "//member.banksteel.com/message/rest/message_user_web",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        data: "businessType=3&messageType=" + s,
        xhrFields: { withCredentials: !0 },
        success: function(e) {
            var t = "";
            if (ids = [], 0 < e.records.length ? $(".msg-bottom").show() : $(".msg-bottom").hide(), 0 < e.records.length)
                for (var a = 0; a < e.records.length; a++) ids.push(e.records[a].id), t += '<li  class="msg-item-li" data-id="' + e.records[a].id + '" data-jumpLink="' + e.records[a].jumpLink + '" data-memberId="' + e.records[a].memberId + '"><dt><span>' + e.records[a].title + " </span>" + e.records[a].showTime + "</dt><dd title='" + e.records[a].content + "'>" + e.records[a].content + "</dd></li>";
            else t = '<li  class="none-msg">暂无消息</li>';
            1 == s ? $(".account-msg").html(t) : 2 == s && $(".msg-wrap").html(t)
        }
    })
}

function toRead(e, t, a) { 0 == a ? $.ajax({ type: "POST", url: "//member.banksteel.com/message/rest/message_user_web/read/" + e, dataType: "json", xhrFields: { withCredentials: !0 }, success: function() { getMessageCount(), window.open(t) } }) : -1 == Object.keys(memberIdInfos).indexOf(a) ? $.toast({ text: "您已不在消息所属会员名下，无法查看", showHideTransition: "fade", allowToastClose: !1, hideAfter: 3e3, stack: 5, position: "top-center", bgColor: "#fdf6ec", textColor: "#e6a23c", textAlign: "center", loader: !1, loaderBg: "#9EC600" }) : a == getCookie("login_memberid") ? $.ajax({ type: "POST", url: "//member.banksteel.com/message/rest/message_user_web/read/" + e, dataType: "json", xhrFields: { withCredentials: !0 }, success: function() { getMessageCount(), window.open(t) } }) : ($.toast({ text: "该消息属于" + memberIdInfos[a] + "会员，请切换公司抬头后再查看", showHideTransition: "fade", allowToastClose: !1, hideAfter: 3e3, stack: 5, position: "top-center", bgColor: "#fdf6ec", textColor: "#e6a23c", textAlign: "center", loader: !1, loaderBg: "#9EC600" }), tooltip.tooltipster("open"), 1 == $._data($(".tooltip")[0], "events").mouseover.length && $(".tooltip").on("mouseover", function() { tooltip.tooltipster("close") })) }

function getNavAdlist(a) {
    $.ajax({
        type: "get",
        //url: "//www.banksteel.com/index/queryAd.jsp?siteName=gg_nav_"+a,
        url: "json/" + a +".json",
        success: function(e) {
            if (e) {
                var t = "";
                e.forEach(function(e) { t += '<li><a target="_blank" href="' + e.link + '"><img width="175" height="60" src="' + e.picUrl + '"></a></li>' }), $("#item-list-" + a).children(".item-list-sub2").html(t)
            }
        }
    })
}
$(".msg-bottom a").click(function() {
	alert("a");
    var e = ids.join(",");
    $.ajax({ type: "POST", xhrFields: { withCredentials: !0 }, url: "//member.banksteel.com/message/rest/message_user_web/read/" + e, dataType: "json", success: function() { getMessageCount() } })
}), 
$(document).on("click", ".msg-item-li", function() { toRead($(this).attr("data-id"), $(this).attr("data-jumpLink"), $(this).attr("data-memberid")) }), 0 < $(".nav-allsort").length && 
(getNavAdlist("jiancai"), 
getNavAdlist("bb"), 
getNavAdlist("cc"), 
getNavAdlist("dd"), 
getNavAdlist("ee"), 
getNavAdlist("ff"), 
getNavAdlist("ii"));
